package com.easy.api.factory.api.request;

import com.alibaba.fastjson.JSON;
import com.easy.api.http.HttpUtils;
import com.easy.api.type.RequestFormat;
import com.easy.api.utils.JsonUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author liuyuan
 * @Date 2020-04-24 21:03
 * @Version 1.0
 */
@Component("postApiMapping")
public class PostApiMapping extends HeaderRequest {

    @Override
    public Object requestStrategy(Object param){
        Map<String, String> requestParam = buildRequestParam(param);
        if (RequestFormat.JSON.equals(requestFormat)) {
            String requestJson = JSON.toJSONString(requestParam);
            String resultJson = HttpUtils.requestJson(requestUrl, null, requestJson, "UTF-8");
            return JsonUtils.fromJson(resultJson, method.getReturnType());
        } else if (RequestFormat.XML.equals(requestFormat)) {
//            String xml = WXPayUtil.mapToXml(requestParam);
        }
        return null;
    }


}
